package com.hamizhong.iflowers.web.action;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.Iterator;
import java.util.List;

import com.hamizhong.iflowers.common.cache.MyCacheFactory;
import com.hamizhong.iflowers.common.cache.MyCacheParam;
import com.hamizhong.iflowers.service.IFestivalService;
import com.hamizhong.iflowers.service.IFlowerCountService;
import com.hamizhong.iflowers.service.IFlowerFloridService;
import com.hamizhong.iflowers.service.IGoodsFestivalMapService;
import com.hamizhong.iflowers.service.IGoodsProductMapService;
import com.hamizhong.iflowers.service.IGoodsPurposeMapService;
import com.hamizhong.iflowers.service.IGoodsService;
import com.hamizhong.iflowers.service.IGoodsTargetMapService;
import com.hamizhong.iflowers.service.IProductService;
import com.hamizhong.iflowers.service.IPurposeService;
import com.hamizhong.iflowers.service.ITargetService;
import com.hamizhong.iflowers.web.base.MyBaseAction;
import com.hamizhong.iflowers.web.vo.ColorVO;
import com.hamizhong.iflowers.web.vo.FestivalVO;
import com.hamizhong.iflowers.web.vo.FlowerCountVO;
import com.hamizhong.iflowers.web.vo.FlowerFloridVO;
import com.hamizhong.iflowers.web.vo.PurposeVO;
import com.hamizhong.iflowers.web.vo.TargetVO;
import com.hamizhong.iflowers.web.vo.VarietyVO;

public class IndexAction extends MyBaseAction {
	private IGoodsService iGoodsService = null;
	private IProductService iProductService = null;
	private IPurposeService iPurposeService = null;
	private IFestivalService iFestivalService = null;
	private ITargetService iTargetService = null;
	private IFlowerFloridService iFlowerFloridService = null;
	private IFlowerCountService iFlowerCountService = null;
	private IGoodsProductMapService iGoodsProductMapService = null;
	private IGoodsPurposeMapService iGoodsPurposeMapService = null;
	private IGoodsFestivalMapService iGoodsFestivalMapService = null;
	private IGoodsTargetMapService iGoodsTargetMapService = null;
	
	public IGoodsService getiGoodsService() {
		return iGoodsService;
	}
	public void setiGoodsService(IGoodsService iGoodsService) {
		this.iGoodsService = iGoodsService;
	}
	public IProductService getiProductService() {
		return iProductService;
	}
	public void setiProductService(IProductService iProductService) {
		this.iProductService = iProductService;
	}
	public IPurposeService getiPurposeService() {
		return iPurposeService;
	}
	public void setiPurposeService(IPurposeService iPurposeService) {
		this.iPurposeService = iPurposeService;
	}
	public IFestivalService getiFestivalService() {
		return iFestivalService;
	}
	public void setiFestivalService(IFestivalService iFestivalService) {
		this.iFestivalService = iFestivalService;
	}
	public ITargetService getiTargetService() {
		return iTargetService;
	}
	public void setiTargetService(ITargetService iTargetService) {
		this.iTargetService = iTargetService;
	}
	public IFlowerFloridService getiFlowerFloridService() {
		return iFlowerFloridService;
	}
	public void setiFlowerFloridService(IFlowerFloridService iFlowerFloridService) {
		this.iFlowerFloridService = iFlowerFloridService;
	}
	public IFlowerCountService getiFlowerCountService() {
		return iFlowerCountService;
	}
	public void setiFlowerCountService(IFlowerCountService iFlowerCountService) {
		this.iFlowerCountService = iFlowerCountService;
	}
	public IGoodsProductMapService getiGoodsProductMapService() {
		return iGoodsProductMapService;
	}
	public void setiGoodsProductMapService(
			IGoodsProductMapService iGoodsProductMapService) {
		this.iGoodsProductMapService = iGoodsProductMapService;
	}
	public IGoodsPurposeMapService getiGoodsPurposeMapService() {
		return iGoodsPurposeMapService;
	}
	public void setiGoodsPurposeMapService(
			IGoodsPurposeMapService iGoodsPurposeMapService) {
		this.iGoodsPurposeMapService = iGoodsPurposeMapService;
	}
	public IGoodsFestivalMapService getiGoodsFestivalMapService() {
		return iGoodsFestivalMapService;
	}
	public void setiGoodsFestivalMapService(
			IGoodsFestivalMapService iGoodsFestivalMapService) {
		this.iGoodsFestivalMapService = iGoodsFestivalMapService;
	}
	public IGoodsTargetMapService getiGoodsTargetMapService() {
		return iGoodsTargetMapService;
	}
	public void setiGoodsTargetMapService(
			IGoodsTargetMapService iGoodsTargetMapService) {
		this.iGoodsTargetMapService = iGoodsTargetMapService;
	}
	
	@Override
	protected String doRequest() {		
		logger.info("----------------- Hello IndexAction -----------------");
		/*读取数据库缓存*/
		//花材
		MyCacheParam myVarietyCacheParam = MyCacheFactory.getInstance().loadCache(MyCacheParam.C_IFLOWERS_VARIETY_DB_ATTR);
		Iterator itVarietyVO = myVarietyCacheParam.getObjValue();
		List<VarietyVO> myVarietyVOList = new ArrayList<VarietyVO>(); 
		try {
			while (itVarietyVO.hasNext()) {
				VarietyVO varietyVO = (VarietyVO) itVarietyVO.next();
				myVarietyVOList.add(varietyVO);
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		Collections.sort(myVarietyVOList, new Comparator<VarietyVO>() {
            public int compare(VarietyVO vo1, VarietyVO vo2) {
                return vo2.getSortId().compareTo(vo1.getSortId());
            }
        });
		getRQ().setAttribute("myVarietyVOList", myVarietyVOList);
		//颜色
		MyCacheParam myColorCacheParam = MyCacheFactory.getInstance().loadCache(MyCacheParam.C_IFLOWERS_COLOR_DB_ATTR);
		Iterator itColorVO = myColorCacheParam.getObjValue();
		List<ColorVO> myColorVOList = new ArrayList<ColorVO>(); 
		try {
			while (itColorVO.hasNext()) {
				ColorVO colorVO = (ColorVO) itColorVO.next();
				myColorVOList.add(colorVO);
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		Collections.sort(myColorVOList, new Comparator<ColorVO>() {
            public int compare(ColorVO vo1, ColorVO vo2) {
                return vo2.getSortId().compareTo(vo1.getSortId());
            }
        });
		getRQ().setAttribute("myColorVOList", myColorVOList);
		//用途
		MyCacheParam myPurposeCacheParam = MyCacheFactory.getInstance().loadCache(MyCacheParam.C_IFLOWERS_PURPOSE_DB_ATTR);
		Iterator itPurposeVO = myPurposeCacheParam.getObjValue();
		List<PurposeVO> myPurposeVOList = new ArrayList<PurposeVO>(); 
		try {
			while (itPurposeVO.hasNext()) {
				PurposeVO purposeVO = (PurposeVO) itPurposeVO.next();
				myPurposeVOList.add(purposeVO);
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		Collections.sort(myPurposeVOList, new Comparator<PurposeVO>() {
            public int compare(PurposeVO vo1, PurposeVO vo2) {
                return vo2.getSortId().compareTo(vo1.getSortId());
            }
        });
		getRQ().setAttribute("myPurposeVOList", myPurposeVOList);
		//节日
		MyCacheParam myFestivalCacheParam = MyCacheFactory.getInstance().loadCache(MyCacheParam.C_IFLOWERS_FESTIVAL_DB_ATTR);
		Iterator itFestivalVO = myFestivalCacheParam.getObjValue();
		List<FestivalVO> myFestivalVOList = new ArrayList<FestivalVO>(); 
		try {
			while (itFestivalVO.hasNext()) {
				FestivalVO festivalVO = (FestivalVO) itFestivalVO.next();
				myFestivalVOList.add(festivalVO);
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		Collections.sort(myFestivalVOList, new Comparator<FestivalVO>() {
            public int compare(FestivalVO vo1, FestivalVO vo2) {
                return vo2.getSortId().compareTo(vo1.getSortId());
            }
        });
		getRQ().setAttribute("myFestivalVOList", myFestivalVOList);
		//赠送对象
		MyCacheParam myTargetCacheParam = MyCacheFactory.getInstance().loadCache(MyCacheParam.C_IFLOWERS_TARGET_DB_ATTR);
		Iterator itTargetVO = myTargetCacheParam.getObjValue();
		List<TargetVO> myTargetVOList = new ArrayList<TargetVO>(); 
		try {
			while (itTargetVO.hasNext()) {
				TargetVO targetVO = (TargetVO) itTargetVO.next();
				myTargetVOList.add(targetVO);
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		Collections.sort(myTargetVOList, new Comparator<TargetVO>() {
            public int compare(TargetVO vo1, TargetVO vo2) {
                return vo2.getSortId().compareTo(vo1.getSortId());
            }
        });
		getRQ().setAttribute("myTargetVOList", myTargetVOList);
		//花语
		MyCacheParam myFlowerFloridCacheParam = MyCacheFactory.getInstance().loadCache(MyCacheParam.C_IFLOWERS_FLOWERFLORID_DB_ATTR);
		Iterator itFlowerFloridVO = myFlowerFloridCacheParam.getObjValue();
		List<FlowerFloridVO> myFlowerFloridVOList = new ArrayList<FlowerFloridVO>(); 
		try {
			while (itFlowerFloridVO.hasNext()) {
				FlowerFloridVO flowerFloridVO = (FlowerFloridVO) itFlowerFloridVO.next();
				myFlowerFloridVOList.add(flowerFloridVO);
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		Collections.sort(myFlowerFloridVOList, new Comparator<FlowerFloridVO>() {
            public int compare(FlowerFloridVO vo1, FlowerFloridVO vo2) {
                return vo2.getSortId().compareTo(vo1.getSortId());
            }
        });
		getRQ().setAttribute("myFlowerFloridVOList", myFlowerFloridVOList);
		//支数
		MyCacheParam myFlowerCountCacheParam = MyCacheFactory.getInstance().loadCache(MyCacheParam.C_IFLOWERS_FLOWERCOUNT_DB_ATTR);
		Iterator itFlowerCountVO = myFlowerCountCacheParam.getObjValue();
		List<FlowerCountVO> myFlowerCountVOList = new ArrayList<FlowerCountVO>(); 
		try {
			while (itFlowerCountVO.hasNext()) {
				FlowerCountVO flowerCountVO = (FlowerCountVO) itFlowerCountVO.next();
				myFlowerCountVOList.add(flowerCountVO);
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		Collections.sort(myFlowerCountVOList, new Comparator<FlowerCountVO>() {
            public int compare(FlowerCountVO vo1, FlowerCountVO vo2) {
                return vo2.getSortId().compareTo(vo1.getSortId());
            }
        });
		getRQ().setAttribute("myFlowerCountVOList", myFlowerCountVOList);
		
		return SUCCESS;
	}

}
